<template>
  <div>
    <el-dialog :visible.sync="visible" v-dialogDrag :title="moduleTitle" :close-on-click-modal="false" class="tl-dialog" width="90%" @open="open" @close="close" :append-to-body="true" top="10px" :modal-append-to-body="true">
      <iframe :src="toaUrl" frameborder="0" width="100%" height="650px"></iframe>
    </el-dialog>
    <el-dialog :visible.sync="attachmentModel.visible" v-dialogDrag :title="attachmentModel.title" :close-on-click-modal="false" class="tl-dialog" width="95%" :append-to-body="true" top="5px" :modal-append-to-body="true">
      <iframe :src="attachmentModel.url" frameborder="0" width="100%" height="700px"></iframe>
    </el-dialog>
  </div>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { getToken } from '@tapui/utils/auth'
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: '流程文件',
      urlPrefix: '/base/processDocumentInfo/',
      url: {
        // 额外的url
        loadFile: '/base/processDocumentInfo/loadFile'
      },
      attachmentModel: {
        url: '',
        title: '',
        visible: false
      },
      toaUrl: '',
      id: 0,
      fileUrl: ''
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
    },
    open() {
      // 为了兼容2.0的附件预览功能，top.openBigDialog
      window.openBigDialog = (obj) => {
        this.attachmentModel.title = obj.title
        this.attachmentModel.url = `/toa/cbo/cboAttachment_componentDispIndex.action?${obj.url.split('?')[1]}`
        this.attachmentModel.visible = true
      }

      let params = {}
      params.url = this.fileUrl
      getAction(this.url.loadFile, params)
        .then((res) => {
          if (res.success) {
            this.id = res.result.id
            this.toaUrl = `/toa/file/fileDirectoryManage_detailView.action?id=${this.id}&isEdit=0&&authtoken=${getToken()}`
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
        .catch(() => {})
    }
  }
}
</script>
